COVID-19 PROJECT¶

In [1]:
import numpy as np
import pandas as pd
import seaborn as sns
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import folium


df = pd.read_csv('case_time_series (2).csv')
  
In [2]:
pip install folium
Requirement already satisfied: folium in c:\users\roshi\anaconda3\lib\site-packages (0.14.0)
Requirement already satisfied: branca>=0.6.0 in c:\users\roshi\anaconda3\lib\site-packages (from folium) (0.6.0)
Requirement already satisfied: jinja2>=2.9 in c:\users\roshi\anaconda3\lib\site-packages (from folium) (2.11.3)
Requirement already satisfied: requests in c:\users\roshi\anaconda3\lib\site-packages (from folium) (2.28.1)
Requirement already satisfied: numpy in c:\users\roshi\anaconda3\lib\site-packages (from folium) (1.21.5)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\roshi\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (2.0.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\roshi\anaconda3\lib\site-packages (from requests->folium) (2022.9.14)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\roshi\anaconda3\lib\site-packages (from requests->folium) (2.0.4)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\roshi\anaconda3\lib\site-packages (from requests->folium) (1.26.11)
Requirement already satisfied: idna<4,>=2.5 in c:\users\roshi\anaconda3\lib\site-packages (from requests->folium) (3.3)
Note: you may need to restart the kernel to use updated packages.
In [3]:
import folium
In [4]:
df
Out[4]:
Date Daily Confirmed Total Confirmed Daily Recovered Total Recovered Daily Deceased Total Deceased
0 30 January 1 1 0 0 0 0
1 31 January 0 1 0 0 0 0
2 01 February 0 1 0 0 0 0
3 02 February 1 2 0 0 0 0
4 03 February 1 3 0 0 0 0
... ... ... ... ... ... ... ...
100 09 May 3175 62865 1414 19301 115 2101
101 10 May 4311 67176 1669 20970 112 2213
102 11 May 3592 70768 1579 22549 81 2294
103 12 May 3562 74330 1905 24454 120 2414
104 13 May 3726 78056 1964 26418 136 2550

105 rows × 7 columns

plotting the graph in sns pairplot¶

In [5]:
sns.pairplot(df)
Out[5]:
<seaborn.axisgrid.PairGrid at 0x2a26ae6c0a0>
In [6]:
import plotly.graph_objects as go
import pandas as pd
 
# reading the database
data = pd.read_csv('case_time_series (2).csv')
 
 
plot = go.Figure(data=[go.Scatter(
    x=data['Date'],
    y=data['Daily Confirmed'],
    mode='markers',)
])
 
# Add dropdown
plot.update_layout(
    updatemenus=[
        dict(
            type="buttons",
            direction="left",
            buttons=list([
                dict(
                    args=["type", "bar"],
                    label="bar plot",
                    method="restyle"
                    
                ),
                dict(
                    args=["type", "line"],
                    label="lineplot",
                    method="restyle"
                ),
                
            ]),
        ),
    ]
)
 
plot.show()
In [7]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

data = pd.read_csv('case_time_series (2).csv')

Y = data.iloc[61:,1].values
R = data.iloc[61:,3].values
D = data.iloc[61:,5].values
X = data.iloc[61:,0]

plt.figure(figsize=(25,8))

ax = plt.axes()
ax.grid(linewidth=0.4, color='#8f8f8f')

ax.set_facecolor("black")
ax.set_xlabel('\nDate',size=25,color='#4bb4f2')
ax.set_ylabel('Number of Confirmed Cases\n',
              size=25,color='#4bb4f2')

plt.xticks(rotation='vertical',size='20',color='red')
plt.yticks(size=20,color='red')
plt.tick_params(size=20,color='red')

for i,j in zip(X,Y):
    ax.annotate(str(j),xy=(i,j+100),color='white',size='13')

ax.annotate('Second Lockdown 15th April',
            xy=(15.2, 860),
            xytext=(19.9,500),
            color='white',
            size='25',
            arrowprops=dict(color='red',
                            linewidth=0.025))

plt.title("COVID-19 IN : Daily Confirmed\n",
         size=50,color='#28a9ff')                  #28a9ff

ax.plot(X,Y,
        color='#1F77B4',
        marker='*',
         linewidth=4,
         markersize=15,
        markeredgecolor='#28a9ff')
Out[7]:
[<matplotlib.lines.Line2D at 0x2a2669cdca0>]
In [34]:
data = pd.read_csv('district (1).csv')


data.head()
re=data.iloc[:15,5].values
de=data.iloc[:15,4].values
co=data.iloc[:15,3].values
x=list(data.iloc[:15,0])

plt.figure(figsize=(13,10))
ax=plt.axes()

ax.set_facecolor('black')
ax.grid(linewidth=0.4, color='#8f8f8f')


plt.xticks(rotation='vertical',size='20',color='black')#ticks of X

plt.yticks(size='20',color='black')


ax.set_xlabel('\nDistrict',size=25,color='#4bb4f2')    #17th may 2020
 
ax.invert_xaxis()  

ax.set_ylabel('No. of cases\n',size=25,color='#4bb4f2')


plt.tick_params(size=20,color='white')


ax.set_title('andhrapradesh District wise breakdown\n',size=50,color='#28a9ff')

plt.bar(x,co,label='re')
plt.bar(x,re,label='re',color='green')
plt.bar(x,de,label='re',color='red')

for i,j in zip(x,co):
	ax.annotate(str(int(j)),xy=(i,j+3),color='white',size='15')

plt.legend(['Confirmed','Recovered','Deceased'],
fontsize=20)
Out[34]:
<matplotlib.legend.Legend at 0x2a271f4b280>
In [35]:
data
Out[35]:
districtData/0/district blank districtData/0/active districtData/0/confirmed districtData/0/deceased districtData/0/recovered
0 anthapur NaN 47 122 4 71
1 chittor NaN 100 177 0 77
2 eastgodavari NaN 13 52 0 39
3 guntur NaN 134 417 8 275
4 kadapa NaN 34 102 0 68
5 krishna NaN 99 367 15 253
6 kurnool NaN 187 611 19 405
7 nellore NaN 53 150 3 94
8 prakasam NaN 3 66 0 63
9 srikakulam NaN 10 14 0 4
10 vishakapatnam NaN 41 75 1 33
11 vizayanagram NaN 7 7 0 0
12 weatgodavari NaN 19 70 0 51

plotting the graph in sunburst¶

In [36]:
import plotly.express as px
import pandas as pd


DISTRICTS = ["westgodavari", "vizianagaram", "visakhapatnam", "srikakulam", "prakasam", "nellore",
        "kurnool", "krishna", "kadapa", "guntur","east godavari","chittor","ananthapur"]

ACTIVE= ["47", "100", "13", "134", "34","99",
        "187", "53", "3", "10", "41","7","19"]      
CONFIRMED = ["122", "177", "52", "417", "102","367" ,"611" ,
        "150", "66", "14", "75", "7","70"]         

RECOVERED = ["4", "0", "0", "8", "0","15",
        "19", "3", "0", "0", "1","1","1"]         


df = pd.DataFrame(dict(DISTRICTS=DISTRICTS, ACTIVE=ACTIVE, CONFIRMED=CONFIRMED, RECOVERED=RECOVERED))

fig = px.sunburst(df, path=['DISTRICTS','ACTIVE','CONFIRMED','RECOVERED'] )

fig.show()
In [37]:
import pandas as pd
df= pd.read_csv('Covid cases in India (3).csv')  #states of covid cases
In [38]:
df
Out[38]:
S. No. Name of State / UT Total Confirmed cases (Indian National) Total Confirmed cases ( Foreign National ) Cured Death
0 1 Andhra Pradesh 12 0 1 0
1 2 Chhattisgarh 6 0 0 0
2 3 Delhi 38 1 6 1
3 4 Gujarat 43 0 0 3
4 5 Haryana 16 14 11 0
5 6 Himachal Pradesh 4 0 0 1
6 7 Karnataka 20 0 3 2
7 8 Kerala 131 7 11 0
8 9 Madhya Pradesh 23 0 0 1
9 10 Maharashtra 144 3 15 4
10 11 Odisha 3 0 0 0
11 12 Puducherry 1 0 0 0
12 13 Punjab 29 0 0 1
13 14 Rajasthan 41 2 3 0
14 15 Tamil Nadu 32 3 1 1
15 16 Telengana 34 11 1 0
16 17 Chandigarh 7 0 0 0
17 18 Jammu and Kashmir 18 0 1 1
18 19 Ladakh 13 0 0 0
19 20 Uttar Pradesh 42 1 11 0
20 21 Uttarakhand 4 0 0 0
21 22 West Bengal 11 0 0 1
22 23 Bihar 7 0 0 1
23 24 Mizoram 1 0 0 0
24 25 Goa 6 0 0 0
25 26 Manipur 1 0 0 0
In [39]:
df['Total Cases']=df['Total Confirmed cases (Indian National)']+df['Total Confirmed cases ( Foreign National )']
In [40]:
data
Out[40]:
districtData/0/district blank districtData/0/active districtData/0/confirmed districtData/0/deceased districtData/0/recovered
0 anthapur NaN 47 122 4 71
1 chittor NaN 100 177 0 77
2 eastgodavari NaN 13 52 0 39
3 guntur NaN 134 417 8 275
4 kadapa NaN 34 102 0 68
5 krishna NaN 99 367 15 253
6 kurnool NaN 187 611 19 405
7 nellore NaN 53 150 3 94
8 prakasam NaN 3 66 0 63
9 srikakulam NaN 10 14 0 4
10 vishakapatnam NaN 41 75 1 33
11 vizayanagram NaN 7 7 0 0
12 weatgodavari NaN 19 70 0 51
In [41]:
total_cases_overall=df['Total Cases'].sum()
print('The total number of cases till now in India is ',total_cases_overall)
The total number of cases till now in India is  729
In [42]:
df['Active Cases']=df['Total Cases']-(df['Death']+df['Cured'])
In [43]:
df
Out[43]:
S. No. Name of State / UT Total Confirmed cases (Indian National) Total Confirmed cases ( Foreign National ) Cured Death Total Cases Active Cases
0 1 Andhra Pradesh 12 0 1 0 12 11
1 2 Chhattisgarh 6 0 0 0 6 6
2 3 Delhi 38 1 6 1 39 32
3 4 Gujarat 43 0 0 3 43 40
4 5 Haryana 16 14 11 0 30 19
5 6 Himachal Pradesh 4 0 0 1 4 3
6 7 Karnataka 20 0 3 2 20 15
7 8 Kerala 131 7 11 0 138 127
8 9 Madhya Pradesh 23 0 0 1 23 22
9 10 Maharashtra 144 3 15 4 147 128
10 11 Odisha 3 0 0 0 3 3
11 12 Puducherry 1 0 0 0 1 1
12 13 Punjab 29 0 0 1 29 28
13 14 Rajasthan 41 2 3 0 43 40
14 15 Tamil Nadu 32 3 1 1 35 33
15 16 Telengana 34 11 1 0 45 44
16 17 Chandigarh 7 0 0 0 7 7
17 18 Jammu and Kashmir 18 0 1 1 18 16
18 19 Ladakh 13 0 0 0 13 13
19 20 Uttar Pradesh 42 1 11 0 43 32
20 21 Uttarakhand 4 0 0 0 4 4
21 22 West Bengal 11 0 0 1 11 10
22 23 Bihar 7 0 0 1 7 6
23 24 Mizoram 1 0 0 0 1 1
24 25 Goa 6 0 0 0 6 6
25 26 Manipur 1 0 0 0 1 1

heat map¶

In [44]:
df.style.background_gradient(cmap='Reds')
Out[44]:
  S. No. Name of State / UT Total Confirmed cases (Indian National) Total Confirmed cases ( Foreign National ) Cured Death Total Cases Active Cases
0 1 Andhra Pradesh 12 0 1 0 12 11
1 2 Chhattisgarh 6 0 0 0 6 6
2 3 Delhi 38 1 6 1 39 32
3 4 Gujarat 43 0 0 3 43 40
4 5 Haryana 16 14 11 0 30 19
5 6 Himachal Pradesh 4 0 0 1 4 3
6 7 Karnataka 20 0 3 2 20 15
7 8 Kerala 131 7 11 0 138 127
8 9 Madhya Pradesh 23 0 0 1 23 22
9 10 Maharashtra 144 3 15 4 147 128
10 11 Odisha 3 0 0 0 3 3
11 12 Puducherry 1 0 0 0 1 1
12 13 Punjab 29 0 0 1 29 28
13 14 Rajasthan 41 2 3 0 43 40
14 15 Tamil Nadu 32 3 1 1 35 33
15 16 Telengana 34 11 1 0 45 44
16 17 Chandigarh 7 0 0 0 7 7
17 18 Jammu and Kashmir 18 0 1 1 18 16
18 19 Ladakh 13 0 0 0 13 13
19 20 Uttar Pradesh 42 1 11 0 43 32
20 21 Uttarakhand 4 0 0 0 4 4
21 22 West Bengal 11 0 0 1 11 10
22 23 Bihar 7 0 0 1 7 6
23 24 Mizoram 1 0 0 0 1 1
24 25 Goa 6 0 0 0 6 6
25 26 Manipur 1 0 0 0 1 1
In [45]:
Total_Active_Cases=df.groupby('Name of State / UT')['Total Cases'].sum().sort_values(ascending=False).to_frame()
In [46]:
Total_Active_Cases
Out[46]:
Total Cases
Name of State / UT
Maharashtra 147
Kerala 138
Telengana 45
Uttar Pradesh 43
Gujarat 43
Rajasthan 43
Delhi 39
Tamil Nadu 35
Haryana 30
Punjab 29
Madhya Pradesh 23
Karnataka 20
Jammu and Kashmir 18
Ladakh 13
Andhra Pradesh 12
West Bengal 11
Bihar 7
Chandigarh 7
Goa 6
Chhattisgarh 6
Himachal Pradesh 4
Uttarakhand 4
Odisha 3
Manipur 1
Mizoram 1
Puducherry 1
In [47]:
Total_Active_Cases.style.background_gradient(cmap='Reds')
Out[47]:
  Total Cases
Name of State / UT  
Maharashtra 147
Kerala 138
Telengana 45
Uttar Pradesh 43
Gujarat 43
Rajasthan 43
Delhi 39
Tamil Nadu 35
Haryana 30
Punjab 29
Madhya Pradesh 23
Karnataka 20
Jammu and Kashmir 18
Ladakh 13
Andhra Pradesh 12
West Bengal 11
Bihar 7
Chandigarh 7
Goa 6
Chhattisgarh 6
Himachal Pradesh 4
Uttarakhand 4
Odisha 3
Manipur 1
Mizoram 1
Puducherry 1
In [48]:
fig=plt.figure(figsize=(20,10),dpi=200)
axes=fig.add_axes([0,0,1,1])
axes.bar(df['Name of State / UT'],df['Total Cases'])
axes.set_title("Total Cases in India")
axes.set_xlabel("Name of State / UT")
axes.set_ylabel("Total Cases")

plt.show()

#plotly
fig=go.Figure()
fig.add_trace(go.Bar(x=df['Name of State / UT'],y=df['Total Cases']))
fig.update_layout(title='Total Cases in India',xaxis=dict(title='Name of State / UT'),yaxis=dict(title='Total Cases'))
In [49]:
data= pd.read_csv('Covid cases in India (3).csv')  #st
In [50]:
data
Out[50]:
S. No. Name of State / UT Total Confirmed cases (Indian National) Total Confirmed cases ( Foreign National ) Cured Death
0 1 Andhra Pradesh 12 0 1 0
1 2 Chhattisgarh 6 0 0 0
2 3 Delhi 38 1 6 1
3 4 Gujarat 43 0 0 3
4 5 Haryana 16 14 11 0
5 6 Himachal Pradesh 4 0 0 1
6 7 Karnataka 20 0 3 2
7 8 Kerala 131 7 11 0
8 9 Madhya Pradesh 23 0 0 1
9 10 Maharashtra 144 3 15 4
10 11 Odisha 3 0 0 0
11 12 Puducherry 1 0 0 0
12 13 Punjab 29 0 0 1
13 14 Rajasthan 41 2 3 0
14 15 Tamil Nadu 32 3 1 1
15 16 Telengana 34 11 1 0
16 17 Chandigarh 7 0 0 0
17 18 Jammu and Kashmir 18 0 1 1
18 19 Ladakh 13 0 0 0
19 20 Uttar Pradesh 42 1 11 0
20 21 Uttarakhand 4 0 0 0
21 22 West Bengal 11 0 0 1
22 23 Bihar 7 0 0 1
23 24 Mizoram 1 0 0 0
24 25 Goa 6 0 0 0
25 26 Manipur 1 0 0 0

To be shown cases in world map¶

In [51]:
Indian_Cord=pd.read_csv('Indian Coordinates.csv')
In [52]:
Indian_Cord
Out[52]:
Name of State / UT Latitude Longitude Unnamed: 3
0 Andaman And Nicobar 11.667026 92.735983 NaN
1 Andhra Pradesh 14.750429 78.570026 NaN
2 Arunachal Pradesh 27.100399 93.616601 NaN
3 Assam 26.749981 94.216667 NaN
4 Bihar 25.785414 87.479973 NaN
5 Chandigarh 30.719997 76.780006 NaN
6 Chhattisgarh 22.090420 82.159987 NaN
7 Dadra And Nagar Haveli 20.266578 73.016618 NaN
8 Delhi 28.669993 77.230004 NaN
9 Goa 15.491997 73.818001 NaN
10 Haryana 28.450006 77.019991 NaN
11 Himachal Pradesh 31.100025 77.166597 NaN
12 Union Territory of Jammu and Kashmir 33.450000 76.240000 NaN
13 Jharkhand 23.800393 86.419986 NaN
14 Karnataka 12.570381 76.919997 NaN
15 Kerala 8.900373 76.569993 NaN
16 Lakshadweep 10.562573 72.636867 NaN
17 Madhya Pradesh 21.300391 76.130019 NaN
18 Maharashtra 19.250232 73.160175 NaN
19 Manipur 24.799971 93.950017 NaN
20 Meghalaya 25.570492 91.880014 NaN
21 Mizoram 23.710399 92.720015 NaN
22 Nagaland 25.666998 94.116570 NaN
23 Orissa 19.820430 85.900017 NaN
24 Puducherry 11.934994 79.830000 NaN
25 Punjab 31.519974 75.980003 NaN
26 Rajasthan 26.449999 74.639981 NaN
27 Sikkim 27.333330 88.616647 NaN
28 Telengana 18.112400 79.019300 NaN
29 Tamil Nadu 12.920386 79.150042 NaN
30 Tripura 23.835404 91.279999 NaN
31 Uttar Pradesh 27.599981 78.050006 NaN
32 Uttarakhand 30.320409 78.050006 NaN
33 West Bengal 22.580390 88.329947 NaN
34 Union Territory of Ladakh 34.100000 77.340000 NaN
In [53]:
dd=pd.merge(Indian_Cord,df,on='Name of State / UT')
In [54]:
dd
Out[54]:
Name of State / UT Latitude Longitude Unnamed: 3 S. No. Total Confirmed cases (Indian National) Total Confirmed cases ( Foreign National ) Cured Death Total Cases Active Cases
0 Andhra Pradesh 14.750429 78.570026 NaN 1 12 0 1 0 12 11
1 Delhi 28.669993 77.230004 NaN 3 38 1 6 1 39 32
2 Haryana 28.450006 77.019991 NaN 5 16 14 11 0 30 19
3 Karnataka 12.570381 76.919997 NaN 7 20 0 3 2 20 15
4 Kerala 8.900373 76.569993 NaN 8 131 7 11 0 138 127
5 Maharashtra 19.250232 73.160175 NaN 10 144 3 15 4 147 128
6 Punjab 31.519974 75.980003 NaN 13 29 0 0 1 29 28
7 Rajasthan 26.449999 74.639981 NaN 14 41 2 3 0 43 40
8 Telengana 18.112400 79.019300 NaN 16 34 11 1 0 45 44
9 Tamil Nadu 12.920386 79.150042 NaN 15 32 3 1 1 35 33
10 Uttar Pradesh 27.599981 78.050006 NaN 20 42 1 11 0 43 32
11 Uttarakhand 30.320409 78.050006 NaN 21 4 0 0 0 4 4
In [55]:
map=folium.Map(location=[20,70],zoom_start=4,tiles='Stamenterrain')

for lat,long,value, name in zip(dd['Latitude'],dd['Longitude'],dd['Total Cases'],dd['Name of State / UT']):
    folium.CircleMarker([lat,long],radius=value*0.8,popup=('<strong>State</strong>: '+str(name).capitalize()+'<br>''<strong>Total Cases</strong>: ' + str(value)+ '<br>'),color='red',fill_color='red',fill_opacity=0.2).add_to(map)
    
In [56]:
map
Out[56]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: